import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-11
 * Time: 12:01
 */
public class min_Operations {
    public static int minOperations(int[] nums, int x) {
        int ret = -1;
        int tmp = 0;
        for (int a : nums) {
            tmp += a;
        }
        if (x > tmp) {
            return -1;
        }
        for (int right = 0, left = 0, sum = 0; right < nums.length; right++) {
            sum += nums[right];//进窗口
            while (sum > tmp - x) {
                sum -= nums[left++];
            }
            if (sum == tmp - x) {
                ret = Math.max(ret, right - left + 1);
            }
        }
        return ret == -1 ? -1 : nums.length - ret;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1, 1};
        System.out.println(minOperations(arr, 3));
    }
}
